package com.cms.service;

import java.util.List;

import com.cms.model.Tactics;
import com.model.Role;
import com.service.AbstractDateService;
import com.utils.dbcp.ConnectionManager;
import com.utils.dbcp.ModelGenerator;

public class TacticsServiceImpl extends AbstractDateService implements TacticsService {

	@Override
	public boolean saveTactics(Tactics tactics, String type) {
		String sql = "";
		if(type.equals("insert"))
		{
			sql = "insert into t_tactics (id, name,spid, toicp, paycode, languageid, typeid, " +
					" type,createtime, createuser, remark) values  " +
					"('"+getTableId("t_tactics")+
					"','"+tactics.getName()+"', '"+tactics.getSpid()+"', '"+tactics.getToicp()+
					"', '"+tactics.getPaycode()+"', '"+tactics.getLanguageid()+
					"', '"+tactics.getTypeid()+"', '"+tactics.getType()+"', '"+tactics.getCreatetime()+
					"', '"+tactics.getCreateuser()+"', '"+tactics.getRemark()+"')";
		}else if(type.equals("update"))
		{
			sql = "update t_tactics set " +
					"name='"+tactics.getName()+
					"',spid = '"+tactics.getSpid()+
					"',toicp = '"+tactics.getToicp()+
					"',paycode = '"+tactics.getPaycode()+
					"',languageid = '"+tactics.getLanguageid()+
					"',typeid = '"+tactics.getTypeid()+
					"',type = '"+tactics.getType()+
					"',remark = '"+tactics.getRemark()+"' where id = '"+tactics.getId()+"'";
		}else if(type.equals("delete"))
		{
			sql = "delete from t_tactics where id='"+tactics.getId()+"'";
		}
		return ConnectionManager.getInstance().execute(base,sql);
	}

	@Override
	public Tactics getTacticss(String id) {
		String sql = "select id,name, spid, toicp, paycode, languageid, typeid,type, createtime, createuser, remark from t_tactics where id ='"+id+"'";
		ModelGenerator<Tactics> model = new ModelGenerator<Tactics>(Tactics.class);
		return model.generate(base, sql.toString());
	}

	@Override
	public List<Tactics> getTacticss() {
		String sql = "select id, name,spid, toicp, paycode, languageid, typeid,type, createtime, createuser, remark from t_tactics order by id desc";
		ModelGenerator<Tactics> model = new ModelGenerator<Tactics>(Tactics.class);
		return model.generateList(base, sql.toString());
	}

}
